package com.apps.apicontroller;

import com.alibaba.fastjson.JSONObject;
import com.apps.common.model.po.ApiResult;
import com.apps.globals.feedback.service.IKupaFeedbackService;
import com.apps.helper.UserConextHelper;
import com.apps.member.model.po.KupaMember;
import com.apps.sannotation.constraints.Email;
import com.apps.sannotation.constraints.Mobile;
import com.apps.saspect.ValidMethod;
import com.apps.thirdparty.email.service.IKupaMailSendService;
import com.apps.thirdparty.sms.service.IKupaSmsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.*;


/**
 * 一些全局接口
 */
@Slf4j
@Api(description = "用户的全局接口")
@RestController
@RequestMapping("/api/global")
public class GlobalApiController {


    @Autowired
    private IKupaMailSendService mailSendService;

    @Autowired
    private IKupaFeedbackService feedbackService;



    @ApiOperation(value = "通用发送邮箱验证码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "email", value = "接收验证码的邮箱", required = true, dataType = "string",paramType = "query")
    })
    @ValidMethod
    @PostMapping("/SendEmailCode")
    public ApiResult<String> sendEmailCode(@Email @RequestParam(value = "email") String email)
    {
        ApiResult<String> result = new ApiResult<>();
        mailSendService.sendValidCodeEmail(email);
        return result.success("发送成功");
    }

    @ApiOperation(value = "意见反馈")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "context", value = "反馈内容", required = true, dataType = "string",paramType = "query"),
            @ApiImplicitParam(name = "contact", value = "联系方式", required = true, dataType = "string",paramType = "query")
    })
    @ValidMethod
    @PostMapping("/SendFeeback")
    public ApiResult<String> sendFeedback(@RequestParam(value = "context") String context,
                                          @RequestParam(value = "contact") String contact)
    {
        ApiResult<String> result = new ApiResult<>();
        KupaMember member=UserConextHelper.getCurrentMember();
        feedbackService.sendFeedBack(null!= member?member.getId():null,contact,context);
        return result.success("感谢您的反馈,我们采纳后会给您适当福利!");
    }


}
